import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:kxy_flutter_app/model/exam_question.dart';

class QuestionHeaderWidget extends StatelessWidget {
  final Question question;
  final int index;
  final int total;

  const QuestionHeaderWidget({
    Key key,
    @required this.question,
    @required this.index,
    @required this.total,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var type = question.type;
    var quesName = getQuesName(type);
    var labelStyle = TextStyle(fontSize: 16, color: Colors.black54);

    return Container(
      height: 50,
      padding: EdgeInsets.symmetric(horizontal: 20),
      decoration: BoxDecoration(
        color: Color.fromRGBO(245, 250, 250, 1),
        border: Border(
          top: BorderSide(
            color: Color.fromRGBO(240, 240, 240, 1),
            width: 1,
          ),
          bottom: BorderSide(
            color: Color.fromRGBO(240, 240, 240, 1),
            width: 1,
          ),
        ),
        // border: Border.symmetric(
        //   vertical: BorderSide(
        //     color: Color.fromRGBO(240, 240, 240, 1),
        //     width: 1,
        //   ),
        // ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(quesName, style: labelStyle),
          indexWidget(index, total, context),
        ],
      ),
    );
  }

  Widget indexWidget(int index, int total, BuildContext context) {
    var primaryStyle = TextStyle(
      fontSize: 30,
      color: Theme.of(context).primaryColor,
    );

    var labelStyle = TextStyle(color: Colors.black54);

    return Row(
      crossAxisAlignment: CrossAxisAlignment.end,
      children: [
        Text((index + 1).toString(), style: primaryStyle),
        Text('/', style: labelStyle),
        Text(total.toString(), style: labelStyle),
      ],
    );
  }

  String getQuesName(int type) {
    switch (type) {
      case 1:
        return '单选题';
      case 2:
        return '多选题';
      case 3:
        return '判断题';
      case 4:
        return '填空题';
      default:
        return '未知题型';
    }
  }
}
